import { _decorator, Component, Node, Label, director } from 'cc';
const { ccclass, property } = _decorator;

import { SSS_Consts } from "../../../Script/Data/SSS_Consts";
import { HeChengDaXiGua_GameData } from "./HeChengDaXiGua_GameData";
import HeChengDaXiGua_GameManager from "./HeChengDaXiGua_GameManager";
import { HeChengDaXiGua_GameStorage } from "./HeChengDaXiGua_GameStorage";
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';

@ccclass('HeChengDaXiGuaGamePanel')
export default class HeChengDaXiGua_GamePanel extends Component {
    static Instance: HeChengDaXiGua_GamePanel;
    @property(Node)
    Button_back: Node | null = null;
    @property(Node)
    Button_refresh: Node | null = null;
    @property(Label)
    Label_score: Label | null = null;
    @property(Label)
    Label_highScore: Label | null = null;
    //    // @property(Node)
    //    // saveTipNode: Node = null; // 保存提示节点
    onLoad() {
        HeChengDaXiGua_GamePanel.Instance = this;
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }
    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }
    Refresh() {
        this.Refresh_score();
    }
    Refresh_score() {
        this.Label_score.string = `${HeChengDaXiGua_GameData.GetScore()}`;
        this.Label_highScore.string = `${HeChengDaXiGua_GameStorage.data.high_score}`;
    }
    //    // // 显示保存提示
    //    // showSaveTip() {
    //    //     // if (this.saveTipNode) {
    //    //     //     this.saveTipNode.active = true;
    //    //     //     this.saveTipNode.opacity = 255;
    //    //     //     tween(this.saveTipNode)
    //    //     //         .delay(1.5)
    //    //     //         .to(0.5, { opacity: 0 })
    //    //     //         .call(() => {
    //    //     //             this.saveTipNode.active = false;
    //    //     //         })
    //    //     //         .start();
    //    //     // }
    //    // }
    AddListener() {
        this.Button_back.on(Node.EventType.TOUCH_END, this.On_Button_back, this);
        this.Button_refresh.on(Node.EventType.TOUCH_END, this.On_Button_refresh, this);

    }
    RemoveListener() {
        this.Button_back.off(Node.EventType.TOUCH_END, this.On_Button_back, this);
        this.Button_refresh.off(Node.EventType.TOUCH_END, this.On_Button_refresh, this);
    }
    On_Button_back() {
        director.loadScene(SSS_Consts.SceneName.MainScene);

        SSS_AudioManager.PlayButtonAudio();
    }
    On_Button_refresh() {
        HeChengDaXiGua_GameManager.Instance.Replay();

        SSS_AudioManager.PlayButtonAudio();
    }
}

// /** 调试 */
window["HeChengDaXiGua_GamePanel"] = HeChengDaXiGua_GamePanel;